package com.tpolteam.tpol.tpol2019.demo.glide;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.request.RequestOptions;
import com.tpolteam.tpol.R;

import androidx.appcompat.app.AppCompatActivity;


public class GlideDemosActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        /**
         * 当 Glide.with() 中传入的 Activity 或 Fragment 实例销毁时，Glide 会自动取消加载并回收资源。
         * Glide中的大部分设置项都可以通过 RequestOptions 类和 apply() 方法来应用到程序中。
         */

        RequestOptions requestOptions = new RequestOptions();
        requestOptions.error(R.mipmap.ic_img_error)
                .placeholder(R.mipmap.ic_img_placeholder);


        ImageView image = findViewById(R.id.image);
        String url = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1550037474222&di=ad275080cf33b7cceb3cfe34f6e63b45&imgtype=0&src=http%3A%2F%2Fimg.kutoo8.com%2Fupload%2Fimage%2F24188279%2F8%2520%25281%2529_960x540.jpg";
        Glide.with(this)
                .load(url)
                .apply(requestOptions)
                .thumbnail(Glide.with(this)
                        .load("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1550648426&di=3a57aa48b40efc98f62a44030a5ce8ad&imgtype=jpg&er=1&src=http%3A%2F%2Fwww.touxiangdaquan.net%2Fuploads%2Fallimg%2Fc160121%2F145333Z6360U0-34T95.jpg"))
                .into(image);

//        Glide.with(this)
//                .load(url)
//                .into(new SimpleTarget<Drawable>() {
//                    @Override
//                    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
//
//                    }
//
//                });

//        FutureTarget<Bitmap> futureTarget =
//                Glide.with(this)
//                        .asBitmap()
//                        .load(url)
//                        .submit(500, 500);
//
//        try {
//            Bitmap bitmap = futureTarget.get();
//        } catch (ExecutionException e) {
//            e.printStackTrace();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }


//        要构造一个 RequestBuilder 对象，你可以通过先调用 Glide.with()然后再调用某一个 as 方法来完成：

        RequestBuilder<Drawable> requestBuilder = Glide.with(this).asDrawable();
//        或先调用 Glide.with() 然后 load()：
//        RequestBuilder<Drawable> requestBuilder = Glide.with(fragment).load(url);


    }
}
